/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.hochschild.sgv.dao.impl;

import java.util.List;
import com.hochschild.sgv.domain.CatalogoDetalle;
import com.hochschild.sgv.dao.CatalogoDao;
import com.hochschild.sgv.util.ConexionBD;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Edson
 */
public class CatalogoDaoImpl implements CatalogoDao {

    public List<CatalogoDetalle> getDetalleCatalogo(String idCatalogo) {
        Connection conn = null;
        ConexionBD conBD = null;
        PreparedStatement pstm = null;
        ResultSet rst = null;
        String SQL = null;
        List catalogoDetalles = new ArrayList();
        try {
            conBD = new ConexionBD();
            conn = conBD.getConnection();
            SQL = "SELECT * from CatalogoDetalle where idCatalogo ='" + idCatalogo + "' order by descripcion";
            pstm = conn.prepareStatement(SQL);
            rst = pstm.executeQuery();
            
            while (rst.next()) {
                CatalogoDetalle bean = new CatalogoDetalle();
                bean.setIdCatalogo(rst.getInt("idCatalogo"));
                bean.setIdItem(rst.getString("idItem"));
                bean.setDescripcion(rst.getString("descripcion"));
                bean.setAbreviatura(rst.getString("abreviatura"));
                catalogoDetalles.add(bean);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            if (pstm != null) {
                try {
                    pstm.close();
                } catch (SQLException ex) {
                    Logger.getLogger(CatalogoDaoImpl.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            if (rst != null) {
                try {
                    rst.close();
                } catch (SQLException ex) {
                    Logger.getLogger(CatalogoDaoImpl.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException ex) {
                    Logger.getLogger(CatalogoDaoImpl.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }

        return catalogoDetalles;
    }
}
